const mysql = require('mysql2/promise');

// 数据库配置
const dbConfig = {
    host: '43.143.253.188',
    port: 3306,
    user: 'nextjs',
    password: 'yEAiRE2jcxTyRBy5',
    database: 'nextjs'
};

async function checkCharactersTable() {
    let connection;

    try {
        connection = await mysql.createConnection(dbConfig);
        console.log('🔌 数据库连接成功');

        // 检查characters表的结构
        console.log('\n📋 检查characters表结构...');

        const [columns] = await connection.execute(`
            SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT
            FROM information_schema.COLUMNS 
            WHERE TABLE_SCHEMA = 'nextjs' 
            AND TABLE_NAME = 'characters'
            AND COLUMN_NAME = 'id'
        `);

        if (columns.length === 0) {
            console.log('❌ 没有找到characters表的id字段');
        } else {
            console.log('✅ characters表id字段信息:');
            columns.forEach(col => {
                console.log(`   - ${col.COLUMN_NAME}: ${col.DATA_TYPE} ${col.IS_NULLABLE === 'NO' ? 'NOT NULL' : 'NULL'} ${col.COLUMN_DEFAULT ? `DEFAULT ${col.COLUMN_DEFAULT}` : ''} ${col.COLUMN_COMMENT ? `(${col.COLUMN_COMMENT})` : ''}`);
            });
        }

        // 检查mount_base表的结构
        console.log('\n📋 检查mount_base表结构...');

        const [mountColumns] = await connection.execute(`
            SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT
            FROM information_schema.COLUMNS 
            WHERE TABLE_SCHEMA = 'nextjs' 
            AND TABLE_NAME = 'mount_base'
            AND COLUMN_NAME = 'id'
        `);

        if (mountColumns.length === 0) {
            console.log('❌ 没有找到mount_base表的id字段');
        } else {
            console.log('✅ mount_base表id字段信息:');
            mountColumns.forEach(col => {
                console.log(`   - ${col.COLUMN_NAME}: ${col.DATA_TYPE} ${col.IS_NULLABLE === 'NO' ? 'NOT NULL' : 'NULL'} ${col.COLUMN_DEFAULT ? `DEFAULT ${col.COLUMN_DEFAULT}` : ''} ${col.COLUMN_COMMENT ? `(${col.COLUMN_COMMENT})` : ''}`);
            });
        }

    } catch (error) {
        console.error('❌ 检查失败:', error.message);
    } finally {
        if (connection) {
            await connection.end();
            console.log('🔌 数据库连接已关闭');
        }
    }
}

// 执行检查
checkCharactersTable();
